﻿@inherits UmbracoTemplatePage
@{
    Layout = "umbLayout.cshtml";

    // If the editor has not explicitly provided the "Page title" property page 
    // then just show the name of the page otherwise show the provided title
    var pageTitle = string.IsNullOrWhiteSpace(CurrentPage.Title)
        ? CurrentPage.Name
        : CurrentPage.Title;

    // Model.Content is the current page that we're on
    // AncestorsOrSelf is all of the ancestors this page has in the tree
    // (1) means: go up to level 1 and stop looking for more ancestors when you get there
    // First() gets the first ancestor found (the home page, on level 1)
    var homePage = CurrentPage.AncestorsOrSelf(1).First();    
    
    // Find all pages with document type alias umbNewsOverview
    // We do that using the plural, umbNewsOverviews (note the extra "s" in the end)
    // Then take the first one, as we know there will only be on news overview page
    var newsOverview = homePage.umbNewsOverviews.First();

    // Similar to above: find all pages with document type umbNewsItem under the news overview page
    // Then order them, first by publishDate (a property the editor can explicitly set on the news item)
    // and then by createDate, which is set by Umbraco automatically when a page gets created.
    var newsItems = newsOverview.umbNewsItems.OrderBy("publishDate desc, createDate desc").Take(5);

}
<!-- Main -->
<div id="main-wrapper">
    <div id="main" class="container">
        <div class="row">
            <div class="12u skel-cell-mainContent">
                <div class="title-background" style="margin-bottom:50px; margin-top:30px">
                    <h2>@pageTitle</h2>
                </div>
                <div class="content">
                        <span class="wrapper-top-left"></span><span class="wrapper-top" ></span><span class="wrapper-left" ></span><span class="wrapper-bottom-left" ></span><span class="wrapper-bottom" ></span><span class="wrapper-bottom-right" ></span><span class="wrapper-right" ></span><span class="wrapper-top-right" ></span>
                    
                    <!-- Content -->
                    <article class="is-page-content">
                        @foreach (var item in newsItems)
                        {

                            // If the editor has not explicitly provided the "Page title" property page 
                            // then just show the name of the page otherwise show the provided title
                            var title = string.IsNullOrWhiteSpace(item.Title) 
                                ? item.Name 
                                : item.Title;


                            // If the editor has not explicitly set the publishDate property then show the create date
                            var dateTime = item.PublishDate == default(DateTime) 
                                ? item.CreateDate 
                                : item.PublishDate;
                            
                            <section>
                                <h3><a href="@item.Url">@title</a></h3>
                                <span class="byline">@item.SubHeader</span>
                                <ul class="meta">
                                    <li class="timestamp">@dateTime.ToString("f")</li>
                                </ul>

                                @if (string.IsNullOrWhiteSpace(item.Image) == false)
                                {
                                    <a href="@item.Url" class="image news-image"><img src="@item.Image" alt="" /></a>
                                }

                                @Umbraco.Truncate(item.BodyText, 200)

                                <a href="@item.Url" class="button">������ ������</a>
                            </section>
                        }
                    </article>
                    <!-- /Content -->
                </div>
            </div>
        </div>
      @*  <div class="row">
            <div class="12u">
                @{ Html.RenderPartial("umbFeatures"); }
            </div>
        </div>*@
    </div>
</div>
<!-- /Main -->